import React from 'react';
import './Icon.css';

const Icon = ({ 
  name = 'default', 
  size = 24, 
  color = 'currentColor',
  className = '' 
}) => {
  // 根据环境确定正确的图标路径
  const getIconPath = (iconName) => {
    // 检查是否在Electron环境中
    if (window.location.protocol === 'file:') {
      // 打包后的Electron环境，使用相对路径
      return `./images/icons/${iconName}.svg`;
    } else {
      // 开发环境，使用绝对路径
      return `/images/icons/${iconName}.svg`;
    }
  };

  const iconPath = getIconPath(name);
  
  return (
    <img 
      src={iconPath}
      alt={`${name} icon`}
      className={`icon ${className}`}
      style={{
        width: size,
        height: size,
        color: color
      }}
    />
  );
};

export default Icon;
